package com.boang.common;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

@Data
@AllArgsConstructor
public class Result<T> implements Serializable {

    //错误码
    private Integer code;

    //消息
    private String message;

    //数据
    private T data;

    public Result(){
        this.code = 200;
        this.message = "success";
    }

    public static <T> Result<T> error(String message) {
        Result result = new Result();
        result.message = message;
        result.code = 0;
        return result;
    }

    public static <T> Result<T> success() {
        Result result = new Result();
        result.message = "success";
        result.code = 200;
        return result;
    }

    public static <T> Result<T> success(Object data) {
        Result result = new Result();
        result.data = data;
        result.message = "success";
        result.code = 200;
        return result;
    }
}